const Router = require("koa-router");

const { auth } = require("../middleware/auth.middleware");
const { validatorParams } = require("../middleware/general.middleware");
const { create, findAll, update } = require("../controller/order.controller");
const { orderFormatError } = require("../constant/error.type");

// 实例化子路由对象
const router = new Router({ prefix: "/order" });

/**
 * 提交订单接口
 */
router.post(
  "/",
  auth,
  validatorParams(
    {
      address_id: "int",
      goods_info: "string",
      total: "number",
    },
    orderFormatError,
  ),
  create,
);

/**
 * 获取订单列表接口
 */
router.get("/", auth, findAll);

/**
 * 更新订单状态接口
 */
router.patch(
  "/:id",
  auth,
  validatorParams(
    {
      status: "number",
    },
    orderFormatError,
  ),
  update,
);

module.exports = router;
